<?php
require_once "Admin/Controller/Controller.php";
require_once "Admin/Model/studentModel.php";

class studentController extends Controller{
	function __Construct(){
		parent::__Construct();
		$this->mod = 'student';
		$this->model=new studentModel();
	}
	function studentlist()
	{
        if (isset($_SESSION['admin'])){
		$data =$this->model->getList();
		$this->assign('student',$data);
		$this->display(); }
	}
	function studentform()
	{if (isset($_SESSION['admin']))
		$this->display(); 
	}
	function add()
	{if (isset($_SESSION['admin'])){
		$data = $_POST;
		$result = $this->model->add($data);
		if($result){
			echo '添加成功 <a href="admin.php?c=student&m=studentlist">如果没有跳转，请点这里跳转</a>';
			header("refresh:3;url='admin.php'");
		}
		else{
			echo "添加失败！<br/>";
			echo "<a href='admin.php?c=student&m=studentform'>返回</a>";
		}}
	}
	function studentmod()
	{if (isset($_SESSION['admin'])){
		$id = $_GET['id'];
		$result = $this->model->getStudentByID($id);
		$this->assign('student',$result);
		$this->display(); }
	}
	function update()
    {
        if (isset($_SESSION['admin'])) {
            $data = $_POST;
            $result = $this->model->update($data);
            if ($result) {
                echo '更新成功 <a href="admin.php?c=student&m=studentlist">如果没有跳转，请点这里跳转</a>';
                header("refresh:3;url='admin.php?c=student&m=studentlist'");
            } else {
                echo "更新失败！<br/>";
                echo "<a href='admin.php?c=student&m=studentmod&id=" . $data['id'] . "'>返回</a>";
            }
        }
    }
	function delete()
    {
        if (isset($_SESSION['admin'])) {
            $id = $_GET['id'];

            $result = $this->model->delete($id);
            if ($result) {
                echo '删除成功 <a href="admin.php?c=student&m=studentlist">如果没有跳转，请点这里跳转</a>';
                header("refresh:3;url='admin.php?c=student&m=studentlistp'");
            } else {
                echo "删除失败！<br/>";
                echo "<a href='admin.php?c=student&m=studentlist'>返回</a>";
            }
        }
    }
}
?>